﻿$(function () {
    $.loading(true);

});

$(window).resize(function () {
    handlerLoadingBox();
    handlerIframeHeight();
});

function getViewPort() {
    var e = window,
        a = 'inner';
    if (!('innerWidth' in window)) {
        a = 'client';
        e = document.documentElement || document.body;
    }

    return {
        width: e[a + 'Width'],
        height: e[a + 'Height']
    };
}
var loadingBoxIndex;

$.loading = function (closemark) {
    if (closemark) {
        $('#eq-loading-spinner').hide();
        return false;
    }
    $('#eq-loading-spinner').show();
};

var loadingLayer;
$.loadingLayer = function (showMark, message) {
    if (!showMark) {
        top.layer.close(loadingLayer);
        return false;
    }
    if (!message)
        message = '努力加载中，请稍候...';
    loadingLayer = top.layer.open({
        title: null,
        closeBtn: 0,
        btn: null,
        offset: 't',
        zIndex: 90000000,
        content: '<div class="mdui-clearfix"><div class="mdui-float-left"><div class="mdui-spinner mdui-spinner-colorful"></div></div><div class="mdui-float-left mdui-m-l-1">' + message + '</div></div>',
        success: function (layero, index) {
            $(layero).addClass('mdui-color-grey-800');
            $(layero).find('.layui-layer-content').css('padding', '20px 20px 8px');
            mdui.mutation();
        }
    });
};

$.successLayer = function (message) {
    if (!message)
        message = '操作成功！';
    top.layer.open({
        title: null,
        closeBtn: 0,
        btn: null,
        offset: 't',
        zIndex: 90000001,
        time: 3000,
        shade:0,
        content: '<div class="mdui-clearfix"><div class="mdui-float-left"><i class="mdui-icon material-icons">check</i></div><div class="mdui-float-left mdui-m-l-1">' + message + '</div></div>',
        success: function (layero, index) {
            $(layero).addClass('mdui-color-theme-600');
        }
    });
};

$.errorLayer = function (message) {
    if (!message)
        message = '发生错误！';
    top.layer.open({
        title: null,
        closeBtn: 0,
        btn: null,
        offset: 't',
        zIndex: 90000003,
        time: 4000,
        shade: 0,
        content: '<div class="mdui-clearfix"><div class="mdui-float-left"><i class="mdui-icon material-icons mdui-text-color-white">error_outline</i></div><div class="mdui-float-left mdui-m-l-1">' + message + '</div></div>',
        success: function (layero, index) {
            $(layero).addClass('mdui-color-pink');
            //$(layero).find('.layui-layer-content').css('padding', '20px 20px 8px');
            //mdui.mutation();
        }
    });
};

$.chatLayer = function (hubMessage) {

    var content = '<div class="mdui-card">';
    content += '<div class="mdui-card-header">';
    content += '<img class="mdui-card-header-avatar" src="' + hubMessage.fromAvatar + '" />';
    content += '<div class="mdui-card-header-title">' + hubMessage.fromUser + '</div>';
    content += '<div class="mdui-card-header-subtitle">' + hubMessage.fromTime + '</div>';
    content += '</div>';
    content += '<div class="mdui-card-content">' + hubMessage.message + '</div>';
    content += '</div>';

    top.layer.open({
        title: null,
        offset: 'rt',
        closeBtn:0,
        zIndex: 90000004,
        shade: 0,
        content: content,
        btn:['我知道了'],
        success: function (layero, index) {
            //$(layero).addClass('mdui-color-yellow-100');
            $(layero).find('.layui-layer-content').css('padding', '0');
            $(layero).find('.layui-layer-btn0').addClass('mdui-text-color-theme');
            //mdui.mutation();
        }
    });
};


$.loadingBox = function (closemark) {
    if (closemark) {
        layer.close(loadingBoxIndex);
        $('.eq-lineloading').hide();
        return false;
    }

    loadingBoxIndex = layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: false,
        zIndex:90000000,
        
        shade:0.2,
        content:$('#loadingBox').html()
    });
    $('.eq-lineloading').show();
    

};



$.successBox = function (msg) {
    if (!msg)
        msg = '操作成功！';

    var sb = '<div class="mdui-color-theme mdui-p-a-2">' + msg + '</div>';

    
    var index = layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: false,
        zIndex: 90000001,

        shade: 0,
        content: sb
    });

    setTimeout(function () { layer.close(index);}, 2500);
    

    //layer.msg(sb);
}



function handlerLoadingBox() {
    var $loadingBox = $("#loadingBox");
    $loadingBox.css("left", (getViewPort().width - $loadingBox.width()) / 2 - 50);
    $loadingBox.css("top", (getViewPort().height - $loadingBox.height()) / 2);
}

function handlerIframeHeight() {
    var $header = $('#eq-header');
    var $tabBar = $('#eq-manage-tab');

    var $iframes = $('#eq-manage-tabcontent').find('iframe');

    var height = getViewPort().height - $header.height() - $tabBar.height() -8;

    $iframes.css('height', height);
}




